Socket
Book a DemoInstallSign in
Socket

cli-qa

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cli-qa

Command-line Questions & Answers

0.3.0
Source
npmnpm
Version published
Weekly downloads
21
600%
Maintainers
1
Weekly downloads
 
Created
Source

cli-qa

Command-line Questions & Answers. Supports color formatting, lists, yes/no confirmations.

Install

$ npm install cli-qa

Usage

var QA = require('cli-qa')

var questions = [
  "{bold}Name:{reset}",
  { title: "Username:", default: process.env.USER },
  { key: "email", title: "E-Mail:", validate: { email: true } },
  { title: "{bold}Favorite foods:{reset}", list: 3 },
  { key: "books", title: "{bold}Favorite books {grey}(Type as much as you want!){reset}{bold}:{reset}", list: true },
  { title: "{yellow}Favorite {green}Fruits{reset}:", commaList: true },
  { key: 'thatsAll', title: "{yellow}{bold}That's all {grey}(yes/no) {yellow}?{reset}", bool: true },
];

QA(questions, function (answers) {
  console.log(answers)
  // => {
  //      "name": "Azer",
  //      "username": "ak",
  //      "email": "azer@roadbeats.com",
  //      "foods": ["falafel", "babi guling", "kebab"],
  //      "favoriteBooks": ["snow", "white castle"],
  //      "thoughts": "let's go somewhere!",
  //      "thatsAll": true
  //    }
})

Styling

Title and description fields can be styled with style-format interface. Here is an example;

QA([{ title: "{green}Yes{reset}/{red}No{reset}?", bool: true }], function (answers) {
  answers[yesNo]
  // => true or false
})

Reference

The list of available options for each question:

  • key: The key that will be used in the answers object. If not specified, it'll be auto-generated.
  • title: Title of the question. styling accepted.
  • list: Specify "true" if a numerical list is expected as an answer.
  • commaList: Specify "true" if a comma-separated list is expected as an answer.
  • bool: Yes/no question? true/false
  • default: Default value if answer is empty.
  • validate: Specify requirements for validating the user input.

Keywords

io

FAQs

Package last updated on 15 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.